<!DOCTYPE html>
<html lang="zh-CN">
<head>
	<meta charset="UTF-8">
	<title>01-this执行问题</title>
	<link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet">
	<script src="https://market-cowen.top/static/react.development.js"></script>
	<script src="https://market-cowen.top/static/react-dom.development.js"></script>
	<script src="https://market-cowen.top/static/babel.min.js"></script>
</head>
<body>
	<div class="container">
		<div id="app"></div>
	</div>
</body>
</html>
<script type="text/babel">
	class App extends React.Component{
		constructor(props){
			super(props);
			console.log('constructor')
		}
		state={num:0}
		incrementEvent=()=>{
			this.setState(state=>({num:state.num+1}))
		}
		unmountEvent=()=>{
			ReactDOM.unmountComponentAtNode(document.getElementById('app'))
		}
		forceEvent=()=>{
			this.forceUpdate();
		}
		componentWillMount(){
			console.log('componentWillMount')
		}
		componentDidMount(){
			console.log('componentDidMount')
		}
		componentWillUnMount(){
			console.log('componentWillUnMount')
		}
		shouldComponentUpdate(props,state){
			console.log(props,state)
			console.log('shouldComponentUpdate')
			return false
		}
		componentWillUpdate(){
			console.log('componentWillUpdate')
		}
		componentDidUpdate(){
			console.log('componentDidUpdate')
		}
		render(){
			console.log('render')
			return (
				<div className="rows" style={{padding:'40px'}}>
					<h4>当前数值<strong className="ml-2 text-danger">{this.state.num}</strong></h4>
					<button className='btn btn-primary' onClick={this.incrementEvent}>点击加1</button>
					<button className='ml-3 btn btn-danger' onClick={this.unmountEvent}>销毁组件</button>		
					<button className='ml-3 btn btn-info' onClick={this.forceEvent}>强制更新</button>		
				</div>
			)
		}
	}
	ReactDOM.render(<App/>,document.getElementById("app"))
</script>